using System.Collections.Generic;
using System.Text;
using System;
using NHibernate;
using NHibernate.Cfg;
using JVLMRP;
namespace JVLMRP 
{
    public class MRPDetailsOrdersService
    {
        ISession session;

        public MRPDetailsOrdersService(ISession session)
        {
            this.session = session;
        }
        public MRPDetailsOrdersService()
        {
            this.session = SessionFactory.GetNewSession();
        }
        public void InsertMrpdetailsorders(MRPDetailsOrders mrpdetailsordersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Save(mrpdetailsordersX);
            tx.Commit();
        }

        public void UpdateMrpdetailsorders(MRPDetailsOrders mrpdetailsordersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Update(mrpdetailsordersX);
            tx.Commit();
        }

        public void DeleteMrpdetailsorders(MRPDetailsOrders mrpdetailsordersX)
        {
            ITransaction tx = session.BeginTransaction();
            session.Delete(mrpdetailsordersX);
            tx.Commit();
        }

        public IList<MRPDetailsOrders> GetAllMrpdetailsorders(Boolean evict)
        {
            IQuery query = session.CreateQuery("select from MRPDetailsOrders");
            IList<MRPDetailsOrders> list = query.List<MRPDetailsOrders>();
            if (evict)
            {
                foreach (MRPDetailsOrders s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }

        public MRPDetailsOrders GetAllMrpdetailsordersByID(String id, Boolean evict)
        {
            IQuery query = session.CreateQuery("select c from MRPDetailsOrders as c where c.Detailorderid= :x");
            query.SetString("x", id);
            MRPDetailsOrders s = (MRPDetailsOrders)query.UniqueResult();
            if (evict)
            {
                session.Evict(s);
            }
            return s;
        }

        public IList<MRPDetailsOrders> GetMrpdetailsordersByQuery(IQuery query, Boolean evict)
        {
            IList<MRPDetailsOrders> list = query.List<MRPDetailsOrders>();
            if (evict)
            {
                foreach (MRPDetailsOrders s in list)
                {
                    session.Evict(s);
                }
            }
            return list;
        }
    }
}
